﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ahao.LeetCode._0700_0799.demo777
{
    public class Class777
    {
        public bool CanTransform(string start, string end)
        {
            int n = start.Length;
            int i = 0, j = 0;
            while (i < n && j < n)
            {
                while (i < n && start[i] == 'X')
                {
                    i++;
                }
                while (j < n && start[j] == 'X')
                {
                    j++;
                }
                if (i < n && j < n)
                {
                    if (start[i] != end[j])
                    {
                        return false;
                    }
                    char c = start[i];
                    if ((c == 'L' && i < j) || (c == 'R' && i > j))
                    {
                        return false;
                    }
                    i++;
                    j++;
                }
            }
            while (i < n)
            {
                if (start[i] != 'X')
                {
                    return false;
                }
                i++;
            }
            while (j < n)
            {
                if (end[j] != 'X')
                {
                    return false;
                }
                j++;
            }
            return true;
        }
    }
}
